home *** CD-ROM | disk | FTP | other *** search
- # include "MWMaca.h"
- # include "MWFileStuff.h"
- # include "MakeWrite.h"
-
- # ifdef debug
- # include "TransDisplay.h"
- # endif
-
-
- /*
- * Prototype for data of empty paragraph
- */
-
- typedef struct EmptyParaData6
- {
- short pTextLen;
- short pFmtLen;
- Format pFormat;
- } EmptyParaData6;
-
-
- EmptyParaData6 emptyParaData =
- {
- 0, /* text length = 0 (no text) */
- 6, /* format data length (1 format) */
- { 0, 12, 0, 1} /* format: pos 0, size 12, style */
- /* plain, application font */
- };
-
-
- UPrintRec uPrintRec; /* not initialized - doesn't matter? */
-
-
- Ruler stdRuler =
- {
- 10, /* left margin */
- 480, /* right margin */
- leftJust, /* justification */
- 10, /* number of tabs */
- 0, /* line spacing = single */
- 10, /* indentation of first line */
- { 40, 80, 120, 160, 200, /* tab values */
- 240, 280, 320, 360, 400 }, /* tab values */
- { 0, 0, 0, 0 } /* four bytes fill */
- };
-
-
-
- Globals6 globals =
- {
- 6, /* MacWrite 4.5 = version 6 */
- 0, /* main doc para count - fill in later */
- 2, /* header para count */
- /* (one ruler + 1 empty text para) */
- 2, /* footer para count */
- /* (one ruler + 1 empty text para) */
- 0, /* title page flag */
- 0, /* unused */
- 0, /* scrap not displayed */
- 0, /* footer not displayed */
- 0, /* header not displayed */
- 0, /* rulers displayed */
- -1, /* active document: -1 tells MacWrite */
- /* to recalc display information */
- 1, /* starting page = 1 */
- 0L, /* free list position - fill in later */
- 8, /* free list length */
- 8, /* # bytes allocated for list */
- { 0, 0, 0, 0, 0, 0, 0, /* unused */
- 0, 0, 0, 0, 0, 0, 0 } /* unused */
- };
-
-
- Windows6 windowVars =
- {
- { 1, 0 }, /* start of selection (para 1, char 0) */
- { 1, 0 }, /* end of selection (para 1, char 0) */
- 0, /* vertical offset */
- 0, /* first paragraph to redraw */
- 0L, /* position of information array */
- /* (filled in later) */
- 0, /* length of information array */
- /* (filled in later) */
- 0L, /* position of line height array */
- /* (filled in later) */
- 0, /* length of line height array */
- /* (filled in later) */
- { -14, 30 }, /* page icon position */
- { -14, 236 }, /* date icon position */
- { -14, 442 }, /* time icon position */
- { -1, -1, -1, -1 }, /* four bytes fill */
- -1, /* redraw ovals (icons) */
- 0, /* don't redraw rulers */
- { -1, -1 }, /* face active when saved */
- /* (-1 = "has never been set") */
- -1 /* font active when saved */
- /* (-1 = "has never been set") */
- };
-
-
- ParaInfo6 rulerParaInfo;
- ParaInfo6 nullTextParaInfo;
-
-
- Boolean
- SetParaInfo (ParaInfo6 *p, short height, Byte status,
- long dataPos, short dataLen, short comFormats)
- {
-
- # ifdef debug
- DisplayString ("\p{SetParaInfo}");
- # endif
-
- p->paraHeight = height;
- p->paraPos = 0;
- p->paraHandle = (long) nil; /* paraHandle is never actually used */
- p->paraStOff.paraOffset = dataPos; /* set this first */
- p->paraStOff.paraStatus = status; /* *then* this! */
- p->paraLen = dataLen;
- p->paraFmts = comFormats;
-
- return (true);
- }
-
-
- /*
- * Write file prelude, using prototype structures.
- * Global variables
- * Universal print record
- * Footer document variables
- * Header document variables
- * Main document varables
- *
- * Some of these will be patched in the postlude.
- *
- * Also write as much of the invariant file contents as possible:
- * Footer document contents (1 ruler + 1 empty text paragraph)
- * Header document contents (1 ruler + 1 empty text paragraph)
- * Initial ruler of main document
- */
-
- Boolean
- WritePrelude (short f)
- {
-
- return (FileWrite (f, (Ptr) &globals, (long) sizeof (Globals6))
- && FileWrite (f, (Ptr) &uPrintRec, (long) sizeof (UPrintRec))
- && FileWrite (f, (Ptr) &windowVars, (long) sizeof (Windows6))
- && FileWrite (f, (Ptr) &windowVars, (long) sizeof (Windows6))
- && FileWrite (f, (Ptr) &windowVars, (long) sizeof (Windows6))
- && ZeroPad (f, 6)
- && FileWrite (f, (Ptr) &stdRuler, (long) sizeof (Ruler))
- && FileWrite (f, (Ptr) &emptyParaData, (long) sizeof (EmptyParaData6))
- && FileWrite (f, (Ptr) &stdRuler, (long) sizeof (Ruler))
- && FileWrite (f, (Ptr) &emptyParaData, (long) sizeof (EmptyParaData6))
- && FileWrite (f, (Ptr) &stdRuler, (long) sizeof (Ruler))
- );
- }
-
-
- /*
- * Write line height array, one entry for each paragraph. First
- * para is always a ruler - write a zero word. Other paras are
- * faked by writing information that there's one line in the para
- * of height 16 (12-point height). MacWrite will fix when it reads
- * the file.
- *
- * paraCount assumed >= 2.
- */
-
- Boolean
- WriteLineHeights (short f, short paraCount)
- {
-
- if (!WriteInteger (f, 0))
- return (false);
-
- while (--paraCount > 0)
- {
- if (!WriteLongint (f, 0x00011010))
- return (false);
- }
-
- return (true);
- }
-
-
- /*
- * Write line height and paragraph info positions and lengths
- */
-
- Boolean
- WriteArrayInfo (short f, long seek, long piPos, short piLen,
- long lhPos, short lhLen)
- {
-
- FileSeek (f, seek);
- return (WriteLongint (f, piPos) && WriteInteger (f, piLen)
- && WriteLongint (f, lhPos) && WriteInteger (f, lhLen));
- }
-
-
- /*
- * Paragraph data are all written now. The line height and paragraph
- * info arrays must now be written, as well as an empty free list.
- * Save the positions of these arrays, as they must be patched into
- * the window variables.
- *
- * The paraCount and paraInfo are for the text paragraphs only.
- * When the main document paragraph count and paragraph information
- * are length are patched into the globals, increment to take
- * into account the initial ruler (written during prelude).
- */
-
- Boolean
- WritePostlude (short f, short paraCount, PIAHandle paraInfo)
- {
- long fLHPos, fPIPos; /* footer line height, para info array pos */
- long hLHPos, hPIPos; /* header line height, para info array pos */
- long mLHPos, mPIPos; /* main line height, para info array pos */
- short paraInfoLen; /* length of main para info array */
- short defInfoLen; /* length of header, footer pi array */
- short defLHLen; /* length of header, footer line height array */
- short mainLHLen; /* length of main line height array */
- long freeListPos; /* free list pos */
- Boolean result;
-
- /*
- * Set up prototype ruler paragraph and null text paragraph
- * information array elements. The position field must be filled
- * in on a per-window basis.
- */
-
- SetParaInfo (&rulerParaInfo, 0, 0, (long) 0x130, 34, 0);
- SetParaInfo (&nullTextParaInfo, 16, 0, (long) 0x152, 10, 0);
-
- /*
- * For footer
- */
-
- fLHPos = FilePos (f);
- if (!WriteLineHeights (f, 2))
- return (false);
-
- fPIPos = FilePos (f);
- if (!FileWrite (f, (Ptr) &rulerParaInfo, (long) sizeof (ParaInfo6))
- || !FileWrite (f, (Ptr) &nullTextParaInfo, (long) sizeof (ParaInfo6)))
- return (false);
-
- /*
- * For header
- */
-
- hLHPos = FilePos (f);
- if (!WriteLineHeights (f, 2))
- return (false);
-
- rulerParaInfo.paraStOff.paraOffset += sizeof (Ruler) + sizeof (EmptyParaData6);
- nullTextParaInfo.paraStOff.paraOffset += sizeof (Ruler) + sizeof (EmptyParaData6);
-
- hPIPos = FilePos (f);
-
- if (!FileWrite (f, (Ptr) &rulerParaInfo, (long) sizeof (ParaInfo6))
- || !FileWrite (f, (Ptr) &nullTextParaInfo, (long) sizeof (ParaInfo6)))
- return (false);
-
- /*
- * For main
- */
-
- mLHPos = FilePos (f);
- if (!WriteLineHeights (f, paraCount + 1))
- return (false);
-
- rulerParaInfo.paraStOff.paraOffset += sizeof (Ruler) + sizeof (EmptyParaData6);
-
- mPIPos = FilePos (f);
-
- if (!FileWrite (f, (Ptr) &rulerParaInfo, (long) sizeof (ParaInfo6)))
- return (false);
-
- paraInfoLen = paraCount * sizeof (ParaInfo6);
- HLock ((Handle) paraInfo);
- result = FileWrite (f, (Ptr) *paraInfo, (long) paraInfoLen);
- HUnlock ((Handle) paraInfo);
- if (!result)
- return (false);
-
- /*
- * Write free list. It's at the end of the file, so set the
- * file EOF here, too.
- */
-
- freeListPos = FilePos (f);
- if (!WriteLongint (f, freeListPos + 8) || !WriteLongint (f, 0L))
- return (false);
-
- (void) SetEOF (f, FilePos (f));
-
- /*
- * Now patch globals and window variables:
- * main doc para count (increment to account for ruler)
- * free list position
- * line height and para info array positions (and para info array
- * length for main document)
- */
-
- FileSeek (f, 2L);
- ++paraCount;
- paraInfoLen += sizeof (ParaInfo6);
- if (!WriteInteger (f, paraCount))
- return (false);
- FileSeek (f, 18L);
- if (!WriteLongint (f, freeListPos))
- return (false);
-
- defInfoLen = 2 * sizeof (ParaInfo6);
- defLHLen = 3 * sizeof (short);
- mainLHLen = sizeof (short) + (paraCount-1) * sizeof (long);
- if (!WriteArrayInfo (f, 172L, fPIPos, defInfoLen, fLHPos, defLHLen)
- || !WriteArrayInfo (f, 218L, hPIPos, defInfoLen, hLHPos, defLHLen)
- || !WriteArrayInfo (f, 264L, mPIPos, paraInfoLen, mLHPos, mainLHLen))
- return (false);
-
- return (true);
- }
-